package com.seal.yoyoshop.dao.impl;

import com.seal.yoyoshop.bin.Top;
import com.seal.yoyoshop.dao.TopDao;
import com.seal.yoyoshop.util.DBUtils;

import java.util.List;

public class TopDaoImpl implements TopDao {
    @Override
    public List<Top> selectTopListByGoodsId(int goodsId) {
        String sql = "SELECT * FROM top WHERE good_id = ?";
        List<Top> topList = DBUtils.query(sql,Top.class,goodsId);
        return topList;
    }

    @Override
    public boolean addTopByTop(Top top) {
        String sql = "INSERT INTO top(type, good_id) VALUES (?, ?)";
        int row = DBUtils.update(sql, top.getType(), top.getGoodId());
        if(row == 1)return true;
        return false;
    }

    @Override
    public boolean deleteTopByTop(Top top) {
        String sql = "DELETE FROM top WHERE type = ? AND good_id = ?";
        int row = DBUtils.update(sql, top.getType(), top.getGoodId());
        if(row == 1)return true;
        return false;
    }
}
